//
//  RMMOrderEvaluationViewController.m
//  Romomo
//
//  Created by puman on 2016/10/25.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMOrderEvaluationViewController.h"
#import "RMMEvaluaSkillTableViewCell.h"
#import "RMMEvaluaView.h"
#import "RMMTableView.h"
#import "RMMEvaluationGoodsTableViewCell.h"
#import "RMMGoodsZhanOrChaiTableViewCell.h"
#import "RMMGoodsEvaluationView.h"
#import "RMMCommonBottomView.h"
#import "RMMDaShangView.h"
#import "RMMPayOrderViewController.h"

NSString *const evaluation = @"点评一下商品或技师吧,您的意见很重要(写够15字才是真爱)";
@interface RMMOrderEvaluationViewController ()<UITableViewDelegate, UITableViewDataSource, TableViewTouchDelegate, UITextViewDelegate,UITextFieldDelegate>

@end

@implementation RMMOrderEvaluationViewController
{
    RMMTableView *_tableView;
    RMMEvaluaView *_evalueView;
    RMMCommonBottomView *_bottomView;
    RMMGoodsEvaluationView *_goodEView;
    RMMDaShangView *_daShangView;
    UITextView *_textView;
    NSDictionary *_skillDic;
    NSArray *_dataArray;
    NSMutableDictionary *_statDic;
    NSMutableDictionary *_statGoodsDic;
    NSMutableDictionary *_moneyDic;
    NSInteger _count;
    NSArray *_bqArray;
    NSInteger _goodsCount;
    NSInteger _buttonTag;
    CGFloat _height;
    BOOL _hide;
}
- (void)dealloc{
    NS_REM(UIKeyboardWillHideNotification, nil);
    NS_REM(UIKeyboardWillShowNotification, nil);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"评价";
    self.view.backgroundColor = kWhiteColor;
    [self addViews];
    [self getSkillDetails];
    // Do any additional setup after loading the view.
}
- (void)getSkillDetails{
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"org_no"] = Org_no;
    parDic[@"emp_id"] = _model.EMP_ID;
    NSString *url = GetSkillDetailUrl;
    [OSRequestManager requestWithUrlString:url parDic:parDic method:GET finish:^(NSDictionary *dataDic) {
        NSString *status = [NSString stringWithFormat:@"%@",dataDic[@"status"]];
        if ([status isEqualToString:@"1"]) {
            _skillDic = [RMMFileManager setValueForDic:dataDic[@"data"]];
            [self getBiaoQian];
        } else {
            [RMMFileManager MBProgressWith:dataDic[@"message"] onView:self.view];
        }
        [_tableView reloadData];
    } error:^(NSError *errors) {
    } view:self.view];
}
- (void)getBiaoQian{
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"org_no"] = Org_no;
    parDic[@"code"] = @"EMP_CODE";
    NSString *url = GetLabelCodeUrl;
    [OSRequestManager requestWithUrlString:url parDic:parDic method:GET finish:^(NSDictionary *dataDic) {
        NSString *status = [NSString stringWithFormat:@"%@",dataDic[@"status"]];
        if ([status isEqualToString:@"1"]) {
            _bqArray = dataDic[@"data"];
        } else {
            [RMMFileManager MBProgressWith:dataDic[@"message"] onView:self.view];
        }
        [_tableView reloadData];
    } error:^(NSError *errors) {
    } view:self.view];
 }
- (void)addViews{
    _height = 120;
    _hide = YES;
    _dataArray = _model.BOOK_DETAIL;
    _bqArray = [NSMutableArray array];
    _statDic = [NSMutableDictionary dictionary];
    _statGoodsDic = [NSMutableDictionary dictionary];
    _moneyDic = [NSMutableDictionary dictionary];
    _tableView = [[RMMTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, kScreenHeight - 64 - 49) style:(UITableViewStylePlain)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.tableViewTouchDelegate = self;
    _tableView.separatorStyle = NO;
    _tableView.tableFooterView = [self addFootView];
    [_tableView registerClass:[RMMEvaluaSkillTableViewCell class] forCellReuseIdentifier:@"Cell"];
    [_tableView registerClass:[RMMEvaluationGoodsTableViewCell class] forCellReuseIdentifier:@"GoodsCell"];
    [_tableView registerClass:[RMMGoodsZhanOrChaiTableViewCell class] forCellReuseIdentifier:@"ZCCell"];
    [self.view addSubview:_tableView];
    
    _bottomView = [[RMMCommonBottomView alloc] initWithFrame:CGRectMake(0, _tableView.bottom, kScreenWideth, 49)];
    BUTTON_S(_bottomView.bottomBut, bottomButClick);
    [self.view addSubview:_bottomView];
    NS_ADD(keyboardShow:, UIKeyboardWillShowNotification, nil);
    NS_ADD(keyboardHide, UIKeyboardWillHideNotification, nil);
    _daShangView = [[RMMDaShangView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWideth, kScreenHeight)];
    _daShangView.textF.delegate =  self;
    TEXTFIELD_S(_daShangView.textF, editorMoney:);
    BUTTON_S(_daShangView.button, payMoneyButClick);
    for (int i = 0; i < 3; i++) {
        UIButton *button = [_daShangView viewWithTag:50 + i];
        BUTTON_S(button, chooseMoneyClick:);
        [_moneyDic setObject:@"0" forKey:[NSString stringWithFormat:@"%ld",button.tag]];
    }
    [keyWidow addSubview:_daShangView];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        return _dataArray.count;
    }
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 75;
    } else if (indexPath.section == 1) {
        return 70;
    }
    return 49;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 44)];
        view.backgroundColor = kCColor;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, view.width - 30, view.height)];
        label.text = @"评价技师";
        label.font = kFont(13);
        label.textColor = COLORFROMCODE(0x9B9B9B, 1);
        [view addSubview:label];
        return view;
    } else if (section == 1) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 44)];
        view.backgroundColor = kCColor;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, view.width - 30, view.height)];
        label.text = @"评价商品";
        label.font = kFont(13);
        label.textColor = COLORFROMCODE(0x9B9B9B, 1);
        [view addSubview:label];
        return view;

    }
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        _evalueView = [[RMMEvaluaView alloc] initWithFrame:CGRectMake(0, _tableView.bottom, kScreenWideth, 120)];
        BUTTON_S(_evalueView.daShangBut, daShangButClick);
        _evalueView.view.hidden = _hide;
        if (!_hide) {
            _evalueView.daShangBut.frame = CGRectMake(kScreenWideth / 2 - 80,_evalueView.view.bottom + kRow, 160, 36);
            NSMutableArray *array = [NSMutableArray array];
            for (NSDictionary *dic in _bqArray) {
                [array addObject:dic[@"LABLE_NAME"]];
            }
            _evalueView.array = _bqArray;
            _evalueView.starCount = [NSNumber numberWithInteger:_count];
            for (int i = 0; i < 8; i++) {
                UIButton *button = [_evalueView.view viewWithTag:10 + i];
                BUTTON_S(button, evaluationButClick:);
                NSString *title = [button titleForState:(UIControlStateNormal)];
                NSString *stat = _statDic[title];
                if ([stat isEqualToString:@"1"]) {
                    [button setImage:[UIImage imageNamed:@"赞-1@3x"] forState:(UIControlStateNormal)];
                    button.backgroundColor = kBasicColor;
                    [button setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
                } else {
                    [button setImage:[UIImage imageNamed:@"赞-2@3x"] forState:(UIControlStateNormal)];
                    button.backgroundColor = kWhiteColor;
                    [button setTitleColor:COLORFROMCODE(0xB5B5B5, 1) forState:(UIControlStateNormal)];
                }
            }
        }
        return _evalueView;
    } else if (section == 1) {
        _goodEView = [[RMMGoodsEvaluationView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 70)];
        _goodEView.starCount = [NSNumber numberWithInteger:_goodsCount];
        _goodEView.type = @"评价商品";
        return _goodEView;
    }
    return nil;
}

- (UIView *)addFootView{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 168)];
    view.backgroundColor = kCColor;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, view.width - 30, 44)];
    label.text = @"写下评论语";
    label.font = kFont(13);
    label.textColor = COLORFROMCODE(0x9B9B9B, 1);
    [view addSubview:label];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, view.width, 124)];
    backView.backgroundColor = kWhiteColor;
    [view addSubview:backView];
    
    _textView = [[UITextView alloc] initWithFrame:CGRectMake(15, kRow, backView.width - 30, backView.height - kMaric)];
    _textView.text = evaluation;
    _textView.textColor = COLORFROMCODE(0xB5B5B5, 1);
    _textView.font = kFont(14);
    _textView.delegate = self;

    [backView addSubview:_textView];
    UIButton *button =  [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(0, 0, kScreenWideth, 40);
    [button setTitle:@"完成" forState:(UIControlStateNormal)];
    [button setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
    BUTTON_S(button, doneBut);
    button.backgroundColor = kBasicColor;
    _textView.inputAccessoryView = button;
    
    return view;
}
- (void)doneBut{
    [_textView resignFirstResponder];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return _height;
    } else if (section == 1) {
        return 70;
    }
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0 || section == 1) {
        return 44;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        RMMEvaluaSkillTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
       // cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.dic = _skillDic;
        return cell;

    } else if (indexPath.section == 1) {
        RMMEvaluationGoodsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GoodsCell"];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
       // cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.array = _dataArray;
        return cell;

    } else {
        RMMGoodsZhanOrChaiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZCCell"];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        cell.dic = _dataArray[indexPath.row];
        cell.badBut.tag = 100 + indexPath.row;
        cell.goodBut.tag = 200 + indexPath.row;
        [_statGoodsDic setObject:@"1" forKey:[NSString stringWithFormat:@"%ld",100 + indexPath.row]];
        BUTTON_S(cell.badBut, badButClick:);
        BUTTON_S(cell.goodBut, goodButClick:);
        [_statGoodsDic setObject:@"1" forKey:[NSString stringWithFormat:@"%ld",200 + indexPath.row]];
        return cell;
    }
}
- (void)bottomButClick{
    [self upEvlautionOrder];
}
// 提交评价
- (void)upEvlautionOrder{
    NSString *cust_id = [RMMFileManager retrunObjWith:[RMMFileManager shareHandle].userDic[@"CUST_ID"]];
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"org_no"] = Org_no;
    parDic[@"remark"] = _textView.text;
    parDic[@"cust_id"] = cust_id;
    parDic[@"order_id"] = _model.ORDER_ID;
    NSMutableArray *detailsArray = [NSMutableArray array];
    NSMutableDictionary *skDic = [NSMutableDictionary dictionary];
    skDic[@"type"] = @"0";
    skDic[@"score"] = [NSString stringWithFormat:@"%.1f",_count / 2.0];
    skDic[@"emp_ser_id"] =_model.EMP_ID;
    skDic[@"is_praise"] = @"0";
    NSMutableArray *stringArray = [NSMutableArray array];
    for (int i = 0; i < 8; i++) {
        UIButton *button = [_evalueView.view viewWithTag:10 + i];
        NSString *key = [button titleForState:(UIControlStateNormal)];
        if ([_statDic[key] isEqualToString:@"1"]) {
            NSString *string = [button titleForState:(UIControlStateNormal)];
            for (NSDictionary *dic in _bqArray) {
                NSString *s = dic[@"LABLE_NAME"];
                if ([string isEqualToString:s]) {
                    [stringArray addObject:dic[@"CODE"]];
                }
            }
        }
    }
    skDic[@"lable_code"] = [stringArray componentsJoinedByString:@","];
    [detailsArray addObject:skDic];
    for (int i = 0; i < _dataArray.count; i++) {
        NSMutableDictionary *goodDic = [NSMutableDictionary dictionary];
        NSDictionary *dic = _dataArray[i];
        goodDic[@"type"] = @"1";
        goodDic[@"score"] = [NSString stringWithFormat:@"%.1f",_goodsCount / 2.0];
        NSString *server_id = [RMMFileManager retrunObjWith:dic[@"SERVER_ID"]];
        goodDic[@"emp_ser_id"] = server_id;
        goodDic[@"lable_code"] = @"";
        NSString *keyA = [NSString stringWithFormat:@"%d",100 + i];
        NSString *keyB = [NSString stringWithFormat:@"%d",200 + i];
        NSNumber *praise = @0;
        if ([_statGoodsDic[keyA]  isEqualToString:@"1"]) {
            praise = @2;
        }
        if ([_statGoodsDic[keyB] isEqualToString:@"1"]) {
            praise = @1;
        }
        goodDic[@"is_praise"] = praise;
        [detailsArray addObject:goodDic];
    }
    parDic[@"details"] = detailsArray;
    NSString *url = EvaluationSkillUrl;
    [OSRequestManager requestWithUrlString:url parDic:parDic method:POST finish:^(NSDictionary *dataDic) {
        NSString *status = [NSString stringWithFormat:@"%@",dataDic[@"status"]];
        if ([status isEqualToString:@"1"]) {
            [MMProgressHUD show];
            [MMProgressHUD dismissWithSuccess:@"评论成功!" title:nil afterDelay:1.0];
            NS_POST(@"ORDERUPDATA", nil, nil);
            NS_POST(@"OREDERDETAILS", nil, nil);
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        } else {
            [RMMFileManager MBProgressWith:dataDic[@"message"] onView:self.view];
        }
        [_tableView reloadData];
    } error:^(NSError *errors) {
    } view:self.view];

}
// 打赏
- (void)daShangButClick{
    [UIView animateWithDuration:kInterval animations:^{
        _daShangView.frame = CGRectMake(0, 0, kScreenWideth, kScreenHeight);
    } completion:^(BOOL finished) {
        
    }];
}
- (void)payMoneyButClick{
    [_daShangView.textF resignFirstResponder];
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"org_no"] = Org_no;
    parDic[@"pay_code"] = _model.IS_HOME;
    parDic[@"cust_id"] = [RMMFileManager shareHandle].userDic[@"CUST_ID"];
    parDic[@"emp_id"] = _skillDic[@"EMP_IMAGE"][@"EMP_ID"];
    parDic[@"order_source"] = @"1";
    if (_daShangView.textF.text.length && [_daShangView.textF.text integerValue] > 0) {
        parDic[@"atm"] = _daShangView.textF.text;
    } else {
        UIButton *button = [_daShangView viewWithTag:_buttonTag];
        NSString *title = [button titleForState:(UIControlStateNormal)];
        parDic[@"atm"] = [title substringToIndex:title.length - 1];
    }
    NSString *url = DaShangSkillUrl;
    [OSRequestManager requestWithUrlString:url parDic:parDic method:GET finish:^(NSDictionary *dataDic) {
        NSString *status = [NSString stringWithFormat:@"%@",dataDic[@"status"]];
        if ([status isEqualToString:@"1"]) {
            [UIView animateWithDuration:kInterval animations:^{
                _daShangView.frame = CGRectMake(0, kScreenHeight, kScreenWideth, kScreenHeight);
            } completion:^(BOOL finished) {
                RMMPayOrderViewController *VC = [[RMMPayOrderViewController alloc] init];
                VC.order_number = dataDic[@"data"];
                VC.type = @"打赏";
                if (_daShangView.textF.text.length && [_daShangView.textF.text integerValue] > 0) {
                    VC.totalPrice = _daShangView.textF.text;
                } else {
                    UIButton *button = [_daShangView viewWithTag:_buttonTag];
                    NSString *title = [button titleForState:(UIControlStateNormal)];
                    VC.totalPrice = [title substringToIndex:title.length - 1];
                }
                [self.navigationController pushViewController:VC animated:YES];
            }];
        } else {
            [RMMFileManager MBProgressWith:dataDic[@"message"] onView:self.view];
        }
        [_tableView reloadData];
        
    } error:^(NSError *errors) {
        
    } view:self.view];
}
- (void)chooseMoneyClick:(UIButton *)button{
    _buttonTag = button.tag;
    NSString *status = [_moneyDic objectForKey:[NSString stringWithFormat:@"%ld",_buttonTag]];
    for (int i = 0; i < 3; i++) {
        UIButton *buttons = [_daShangView viewWithTag:50 + i];
        if (buttons.tag == _buttonTag) {
            if ([status isEqualToString:@"0"]) {
                buttons.backgroundColor = kBasicColor;
                [buttons setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
                [_moneyDic setObject:@"1" forKey:[NSString stringWithFormat:@"%ld",_buttonTag]];
                if (!_daShangView.textF.text.length) {
                    [self buttonOn];
                }
            } else {
                buttons.backgroundColor = kWhiteColor;
                [buttons setTitleColor:kBasicColor forState:(UIControlStateNormal)];
                [_moneyDic setObject:@"0" forKey:[NSString stringWithFormat:@"%ld",_buttonTag]];
                if (!_daShangView.textF.text.length) {
                    [self buttonOff];
                }
            }
        } else {
            buttons.backgroundColor = kWhiteColor;
            [buttons setTitleColor:kBasicColor forState:(UIControlStateNormal)];
            [_moneyDic setObject:@"0" forKey:[NSString stringWithFormat:@"%ld",buttons.tag]];
        }
    }
}
- (void)buttonOn{
    [_daShangView.button setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
    _daShangView.button.backgroundColor = kBasicColor;
    _daShangView.button.userInteractionEnabled = YES;
}
- (void)buttonOff{
    [_daShangView.button setTitleColor:COLORFROMCODE(0xB5B5B5, 1) forState:(UIControlStateNormal)];
    _daShangView.button.backgroundColor = kWhiteColor;
    _daShangView.button.userInteractionEnabled = NO;
}

- (void)editorMoney:(UITextField *)textF{
    if (_daShangView.textF.text.length) {
        _daShangView.button.backgroundColor = kBasicColor;
        _daShangView.button.userInteractionEnabled = YES;
        [_daShangView.button setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
    } else {
        NSMutableArray *array =  [NSMutableArray array];
        for (NSString *key in _moneyDic) {
            [array addObject:_moneyDic[key]];
        }
        if ([array containsObject:@"1"]) {
            _daShangView.button.backgroundColor = kBasicColor;
            _daShangView.button.userInteractionEnabled = YES;
            [_daShangView.button setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
        } else {
            _daShangView.button.backgroundColor = kWhiteColor;
            _daShangView.button.userInteractionEnabled = NO;
            [_daShangView.button setTitleColor:COLORFROMCODE(0xB5B5B5, 1) forState:(UIControlStateNormal)];
        }
    }
}
// 踩
- (void)badButClick:(UIButton *)button{
    NSString *key = [NSString stringWithFormat:@"%ld",button.tag];
    NSString *stat = _statGoodsDic[key];
    UIButton *buttons =[self.view viewWithTag:button.tag + 100];
    [_statGoodsDic setObject:@"0" forKey:[NSString stringWithFormat:@"%ld",button.tag + 100]];
    [buttons setImage:[UIImage imageNamed:@"1推荐@3x"] forState:(UIControlStateNormal)];
    if ([stat isEqualToString:@"0"]) {
        [_statGoodsDic setObject:@"1" forKey:key];
        [button setImage:[UIImage imageNamed:@"已踩@3x"] forState:(UIControlStateNormal)];
    } else {
        [_statGoodsDic setObject:@"0" forKey:key];
        [button setImage:[UIImage imageNamed:@"1踩@3x"] forState:(UIControlStateNormal)];
    }
    [self isCanUpData];
}
// 赞
- (void)goodButClick:(UIButton *)button{
    UIButton *buttons =[self.view viewWithTag:button.tag - 100];
    [buttons setImage:[UIImage imageNamed:@"1踩@3x"] forState:(UIControlStateNormal)];
    NSString *key = [NSString stringWithFormat:@"%ld",button.tag];
    [_statGoodsDic setObject:@"0" forKey:[NSString stringWithFormat:@"%ld",button.tag - 100]];
    NSString *stat = _statGoodsDic[key];
    if ([stat isEqualToString:@"0"]) {
        [_statGoodsDic setObject:@"1" forKey:key];
        [button setImage:[UIImage imageNamed:@"已推荐@3x"] forState:(UIControlStateNormal)];
    } else {
        [_statGoodsDic setObject:@"0" forKey:key];
        [button setImage:[UIImage imageNamed:@"1推荐@3x"] forState:(UIControlStateNormal)];
        
    }
    [self isCanUpData];
}
- (void)isCanUpData{
    if (_goodsCount > 0 && _count > 0) {
        NSMutableArray *array = [NSMutableArray array];
        for (NSString *key in _statGoodsDic) {
            NSString *status = _statGoodsDic[key];
            [array addObject:status];
        }
        if ([array containsObject:@"1"]) {
            _bottomView.bottomBut.backgroundColor = kBasicColor;
            _bottomView.bottomBut.userInteractionEnabled = YES;
            [_bottomView.bottomBut setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
        } else {
            _bottomView.bottomBut.backgroundColor = RGBA(237, 238, 239, 1);
            _bottomView.bottomBut.userInteractionEnabled = NO;
            [_bottomView.bottomBut setTitleColor:RGBA(212, 213, 214, 1) forState:(UIControlStateNormal)];
        }
    } else {
        _bottomView.bottomBut.backgroundColor = RGBA(237, 238, 239, 1);
        _bottomView.bottomBut.userInteractionEnabled = NO;
        [_bottomView.bottomBut setTitleColor:RGBA(212, 213, 214, 1) forState:(UIControlStateNormal)];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
// 评论
- (void)evaluationButClick:(UIButton *)button{
    NSString *title = [button titleForState:(UIControlStateNormal)];
    NSString *stat = _statDic[title];
    if ([stat isEqualToString:@"1"]) {
        _statDic[title] = @"0";
    } else {
        _statDic[title] = @"1";
    }
    for (int i = 0; i < 8; i++) {
        UIButton *buttons = [_evalueView.view viewWithTag:10 + i];
        NSString *key = [buttons titleForState:(UIControlStateNormal)];
        if ([_statDic[key] isEqualToString:@"1"]) {
            [buttons setImage:[UIImage imageNamed:@"赞-1@3x"] forState:(UIControlStateNormal)];
            buttons.backgroundColor = kBasicColor;
            [buttons setTitleColor:kWhiteColor forState:(UIControlStateNormal)];

        } else {
            [buttons setImage:[UIImage imageNamed:@"赞-2@3x"] forState:(UIControlStateNormal)];
            buttons.backgroundColor = kWhiteColor;
            [buttons setTitleColor:COLORFROMCODE(0xB5B5B5, 1) forState:(UIControlStateNormal)];

        }
    }
}
- (void)tableView:(UITableView *)tableView touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:_evalueView];
    CGFloat x = point.x;
    CGFloat y = point.y;
    CGFloat w = (kScreenWideth - 40 - 125) / 2;
    if (y >=  17.5 && y <= 67.5) {
        if (x >= w - 5 && x <= w + 40 + 125 + 50) {
            NSInteger count = (x - (w - 5))/ 17.5 + 1;
            if (_count != count) {
                _count = count;
                if (_count > 10) {
                    _count = 10;
                }
                if (_hide) {
                    _hide = NO;

                }
                _height = 235;
                [_tableView reloadData];
            }
            [self isCanUpData];
        }
    }
    if (y >= 130 + _height && y <= 180 + _height) {
        if (x >= w - 5 && x <= w + 40 + 125 + 50) {
            NSInteger count = (x - (w - 5))/ 17.5 + 1;
            if (_goodsCount != count) {
                _goodsCount = count;
                if (_goodsCount > 10) {
                    _goodsCount = 10;
                }
            }
            [self isCanUpData];
            [_tableView reloadData];
        }
    }
}
// 键盘出现消失
- (void)keyboardShow:(NSNotification *)notification{
    if (_textView.isFirstResponder) {
        NSDictionary *userInfo = [notification userInfo];
        NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
        CGRect rect = [value CGRectValue];
        CGFloat height = rect.size.height;
        [UIView animateWithDuration:kInterval animations:^{
            _tableView.frame = CGRectMake(0, - height, kScreenWideth, kScreenHeight  -  64 - 49);
        } completion:^(BOOL finished) {
            
        }];
    }
}
- (void)keyboardHide{
    if (_tableView.top != 0) {
        [UIView animateWithDuration:kInterval animations:^{
            _tableView.frame = CGRectMake(0, 0, kScreenWideth, kScreenHeight  -  64 - 49);
        } completion:^(BOOL finished) {
            
        }];
    }

}
-  (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:evaluation]) {
        textView.text = @"";
        textView.textColor = COLORFROMCODE(0x2C2C2C, 1);
    }
    return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@""]) {
        textView.text = evaluation;
        textView.textColor = COLORFROMCODE(0xB5B5B5, 1);
    }

    return YES;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
